/**
 * Created by python on 19-2-27.
 */
const HOST = 'http://127.0.0.1:8000';


Vue.filter('str2date', function (value) {
    return new Date(value);
});

Vue.filter('date2ymd', function (value) {
    return value.getFullYear()+ "-" + (value.getMonth() + 1) + "-" + value.getDate();
});


Vue.filter('date2hms', function (value) {
    return value.getHours()+ ":" + value.getMinutes() + ":" + value.getSeconds();
});

// 头条列表月日
Vue.filter('date_md', function (value) {
    return  (value.getMonth() + 1) + "月" + value.getDate() + '日';
});

// 头条列表时分
Vue.filter('date_hm', function (value) {
    return value.getHours()+ ":" + value.getMinutes();
});


const WEEK = ["周日","周一","周二","周三","周四","周五","周六"];
Vue.filter('date2week', function (value) {
    return WEEK[value.getDay()];
});


function get_query_string(key, defval){
    var reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURI(r[2]);
    }
    return defval;
}

Vue.filter('date2ymdhm', function (value) {
    return value.getFullYear() + "-" + (value.getMonth() + 1) + "-" + value.getDate() + " " + value.getHours() + ":" + value.getMinutes();
});
Vue.filter("date", function (value) {
    let oldDate = new Date(value);
    let newDate = new Date();
    // console.log((newDate.getTime()) / 1000)
    if(oldDate == 'Thu Jan 01 1970 08:00:00 GMT+0800 (CST)'){
        return "暂时无人"
    }
    var dayNum = '';
    var getTime = (newDate.getTime() - oldDate.getTime()) / 1000;
    if (getTime < 60 * 5) {
        dayNum = "刚刚";
    } else if (getTime >= 60 * 5 && getTime < 60 * 60) {
        dayNum = parseInt(getTime / 60) + "分钟前";
    } else if (getTime >= 3600 && getTime < 3600 * 24) {
        dayNum = parseInt(getTime / 3600) + "小时前";
    } else if (getTime >= 3600 * 24 && getTime < 3600 * 24 * 30) {
        dayNum = parseInt(getTime / 3600 / 24) + "天前";
    } else if (getTime >= 3600 * 24 * 30 && getTime < 3600 * 24 * 30 * 12) {
        dayNum = parseInt(getTime / 3600 / 24 / 30) + "个月前";
    } else if (getTime >= 3600 * 24 * 30 * 12) {
        dayNum = parseInt(getTime / 3600 / 24 / 30 / 12) + "年前";
    }
    // let year = oldDate.getFullYear();
    // let month = oldDate.getMonth();
    // let day = oldDate.getDate();
    // let hour = oldDate.getHours();
    // let minute = oldDate.getMinutes();
    // let second = oldDate.getSeconds();
    return dayNum
})

Vue.filter('p_a', function (value) {
    return value.substring(0,10)
});